package com.eca.emas.daemon;

import java.io.IOException;
import java.util.ArrayList;

import com.eca.emas.daemon.shared.EMASMailManager;
import com.eca.emas.daemon.shared.Sensor;
import com.jcraft.jsch.JSchException;

public class WiregateServer {

	private ArrayList<Sensor> sensors;

	private String hostOrIP;
	private String password;
	private int location_id;

	public WiregateServer(String hostOrIP, String password, int location_id) {
		this.hostOrIP = hostOrIP;
		this.password = password;
		this.location_id = location_id;
	}

	public boolean updateSensorsViaSSH() {
		SSHConnector connector = new SSHConnector(password, hostOrIP);
		try {
			sensors = connector.getAllSensors();
		} catch (IOException e) {
			e.printStackTrace();
			EMASMailManager.getInstance().sendErrorMessageToAllRecipients(EMASMailManager.ERROR_WIREGATE +" IP: "+hostOrIP, e);
			return false;
		} catch (JSchException e) {
			e.printStackTrace();
			EMASMailManager.getInstance().sendErrorMessageToAllRecipients(EMASMailManager.ERROR_WIREGATE +" IP: "+hostOrIP, e);
			return false;
		}
		return true;
	}

	public ArrayList<Sensor> getSensors() {
		return sensors;
	}

	public void setSensors(ArrayList<Sensor> sensors) {
		this.sensors = sensors;
	}

	public String getHostOrIP() {
		return hostOrIP;
	}

	public void setHostOrIP(String hostOrIP) {
		this.hostOrIP = hostOrIP;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public int getLocation_id() {
		return location_id;
	}

	public void setLocation_id(int location_id) {
		this.location_id = location_id;
	}
}
